#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time   : 2021/3/25 23:09
# @Author : cjw
import requests


# 代理：原理，通过第三方的机器去发送请求
# 59.37.18.243:3128

def get_baidu(proxies=None):
	headers = {
		'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36'
	}
	resp = requests.get('https://www.baidu.com/', proxies=proxies, headers=headers, verify=False)
	resp.encoding = 'utf-8'
	print(resp.text)
	resp.close()


def get_proxy_ip():
	url = 'http://119.45.154.90:5010/get/'
	resp = requests.get(url)
	proxy_ip = resp.json()['proxy']
	resp.close()
	return proxy_ip


if __name__ == '__main__':
	# 代理
	proxies = {
		'http': get_proxy_ip()
	}
	print(proxies)
	get_baidu(proxies)
